<?php
function chk_flag1Fn($SQL,$regkind2='') {
	global $db,$js,$_ZEAI,$_SESSION,$_REG,$pwd,$jumpurl,$server_openid,$loginip;
	$row = $db->ROW(__TBL_USER__,"id,pwd,flag,kind,sex,ifadm,openid",$SQL,'name');
	if ($row){
		if($pwd==$row['pwd'] || $row['flag']==2){
			setcookie("cook_uid",$row['id'],time()+31536000,"/",$_ZEAI['CookDomain']);
			setcookie("cook_pwd",$row['pwd'],time()+31536000,"/",$_ZEAI['CookDomain']);
			setcookie("cook_sex",$row['sex'],time()+31536000,"/",$_ZEAI['CookDomain']);
			setcookie("cook_ifadm",$row['ifadm'],time()+31536000,"/",$_ZEAI['CookDomain']);
		}		
		if($row['flag'] == 1 || $row['flag'] == -2){
			if($row['kind']==2){
				$msg='当前帐号用户类型为【线下】<br>请联系管理员改为【线上】再来登录';
				if($js==1){
					json_exit(array('flag'=>0,'msg'=>$msg));
				}else{
					callmsg($msg,HOST);
				}
			}else{
				//提交用户名注册
				if ($_REG['reg_kind']==2 && $regkind2 == 2 && $row['pwd']!=$pwd){
					json_exit(array('flag'=>0,'msg'=>'当前帐号已注册，请检查密码是否正确<br>或更换其他用户名'));
				}
				//正常，跳转登录成功
				setcookie("cook_uid",$row['id'],time()+31536000,"/",$_ZEAI['CookDomain']);
				setcookie("cook_pwd",$row['pwd'],time()+31536000,"/",$_ZEAI['CookDomain']);
				setcookie("cook_sex",$row['sex'],time()+31536000,"/",$_ZEAI['CookDomain']);
				setcookie("cook_ifadm",$row['ifadm'],time()+31536000,"/",$_ZEAI['CookDomain']);
				//为空自动更新openid v8.2
				if(is_weixin()){
					if(str_len($server_openid)>20 && empty($row['openid'])){
						$row2 = $db->ROW(__TBL_USER__,"id","openid='".$server_openid."'");
						if (!$row2){
							$SQL2 = ",openid='$server_openid'";
						}
					}
				}
				$db->query("UPDATE ".__TBL_USER__." SET endtime=".ADDTIME.",endip='$loginip',logincount=logincount+1".$SQL2." WHERE id=".$row['id']);
				unset($_SESSION["Zeai_cn__verify"]);
				unset($_SESSION["Zeai_cn__mob"]);
				//$jumpurl = trimhtml(urldecode(HOST.$_SERVER['REQUEST_URI']));
				$jumpurl = trimhtml(urldecode($jumpurl));
				$jumpurl = (empty($jumpurl))?a('{"kind":"my"}'):$jumpurl;// || strpos(SELF,'reg_alone') !== false 
				if($js==1){
					json_exit(array('flag'=>'logined','msg'=>'登录成功','jumpurl'=>$jumpurl));
				}else{
					header("Location: $jumpurl");exit;
				}
			}
		}elseif($row['flag'] == -1){
			$msg='当前帐号已被锁定或注销';
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>$msg));
			}else{
				callmsg($msg,HOST);
			}
		}elseif($row['flag'] == 0){
			$msg='当前帐号已经注册，请等待帐号审核';
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>$msg));
			}else{
				callmsg($msg,HOST);
			}
		}
	}
	return $row['flag'];//专为login页面使用
}
?>